package one.bugu.android.demon.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import one.bugu.android.demon.R;

public class DialogReward extends Dialog{

    private Context mContext;
    private boolean isCancelable;
    private boolean isShow = false;
    private DialogHint.OnDialogVersionListener onDialogVersionListener;
    private TextView titleTextView;
    private TextView cententTextView;
    private View lineView;
    private Button cancelBtn;
    private Button okBtn;
    private String content;
    private String title;

    private TextView userCreationTxt;
    private TextView userCreationNumTxt;
    private TextView newUserTxt;
    private TextView newUserNumTxt;
    private TextView messageTxt;
    private RelativeLayout creationContent;
    private RelativeLayout newContent;

    private String userCreation;
    private String userCreationNum;
    private String newUser;
    private String newUserNum;
    private String message;

    public DialogReward(Context context, String message,String userCreation , String userCreationNum, boolean isCancelable, boolean isShow) {
        super(context, com.juefeng.android.framework.R.style.DialogTheme);
        this.mContext = context;
        this.userCreationNum = userCreationNum;
        this.userCreation = userCreation;
        this.isCancelable = isCancelable;
        this.isShow = isShow;
        this.message = message;
        initView();
        setCancelable(isCancelable);
        setCanceledOnTouchOutside(isCancelable);
    }

    public DialogReward(Context context, String message,String newUser , String newUserNum, boolean isCancelable) {
        super(context, com.juefeng.android.framework.R.style.DialogTheme);
        this.mContext = context;
        this.newUser = newUser;
        this.newUserNum = newUserNum;
        this.isCancelable = isCancelable;
        this.message = message;
        initView();
        setCancelable(isCancelable);
        setCanceledOnTouchOutside(isCancelable);
    }

    public DialogReward(Context context, String message,String newUser , String newUserNum, String userCreation , String userCreationNum, boolean isCancelable) {
        super(context, com.juefeng.android.framework.R.style.DialogTheme);
        this.mContext = context;
        this.userCreationNum = userCreationNum;
        this.userCreation = userCreation;
        this.newUser = newUser;
        this.newUserNum = newUserNum;
        this.isCancelable = isCancelable;
        this.message = message;

        initView();
        setCancelable(isCancelable);
        setCanceledOnTouchOutside(isCancelable);
    }

    public DialogReward(Context context, String content, boolean isCancelable) {
        super(context, com.juefeng.android.framework.R.style.DialogTheme);
        this.mContext = context;
        this.content = content;
        this.isCancelable = isCancelable;
        initView();
        setCancelable(isCancelable);
        setCanceledOnTouchOutside(isCancelable);
    }

    private void initView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_reward,null);
        setContentView(view);
        titleTextView = view.findViewById(R.id.title);
        cancelBtn = view.findViewById(R.id.negativeButton);
        okBtn = view.findViewById(R.id.positiveButton);
        lineView = view.findViewById(R.id.line);
        creationContent = view.findViewById(R.id.creationContent);
        newContent = view.findViewById(R.id.newContent);
        cententTextView = view.findViewById(R.id.message);

        userCreationTxt = view.findViewById(R.id.userCreation_txt);
        userCreationNumTxt = view.findViewById(R.id.userCreation_num);
        newUserTxt = view.findViewById(R.id.newUser_txt);
        newUserNumTxt = view.findViewById(R.id.newUser_num);

        userCreationTxt.setText(userCreation);
        userCreationNumTxt.setText(userCreationNum);
        newUserTxt.setText(newUser);
        newUserNumTxt.setText(newUserNum);

        titleTextView.setText(title);
        cententTextView.setText(message);
        if (!isCancelable){
            cancelBtn.setVisibility(View.GONE);
            lineView.setVisibility(View.GONE);
        }else{
            cancelBtn.setVisibility(View.VISIBLE);
            lineView.setVisibility(View.VISIBLE);
        }

        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        WindowManager wm = this.getWindow().getWindowManager();
        int width = wm.getDefaultDisplay().getWidth();
        lp.width = width - 100;
        dialogWindow.setAttributes(lp);

        okBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDialogVersionListener!=null){
                    onDialogVersionListener.onSure();
                }
                dismiss();
            }
        });
        cancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDialogVersionListener!=null){
                    onDialogVersionListener.onCancel();
                }
                dismiss();
            }
        });
        setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (onDialogVersionListener!=null){
                    onDialogVersionListener.onCancel();
                }
                dismiss();
            }
        });
    }

    public DialogHint.OnDialogVersionListener getOnDialogVersionListener() {
        return onDialogVersionListener;
    }

    public void setOnDialogVersionListener(DialogHint.OnDialogVersionListener onDialogVersionListener) {
        this.onDialogVersionListener = onDialogVersionListener;
    }

    public void setContent(String str) {
        this.content = content;
        this.cententTextView.setText(str);
    }

    public interface OnDialogVersionListener{
        void onSure();
        void onCancel();
    }

    public void setCancleText(String str){
        cancelBtn.setText(str);
    }

    public void setOkText(String str){
        okBtn.setText(str);
    }
}
